package com.example.administrator.newjiajiesong;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.administrator.newjiajiesong.base.BaseActivity;
import com.example.administrator.newjiajiesong.main.activity.LoginActivity;
import com.example.administrator.newjiajiesong.test.testmvpfragment;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainActivity extends BaseActivity implements View.OnClickListener {

    /**
     * 测试登录
     */
    private Button mCehsidenglu;
    /**
     * mvpfragment测试
     */
    private Button mFragmentceshi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    public void onAction(View view) throws IOException {
        //创建retrofit对象
        Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.BASE_URL).addConverterFactory(GsonConverterFactory.create()).build();
        //获取UserMgrService对象
        UserMgrService userMgrService = retrofit.create(UserMgrService.class);
        //调用登录login方法
        Call<UserInfoModel> call = userMgrService.login("13484474409", "123456");
        call.enqueue(new Callback<UserInfoModel>() {
            @Override
            public void onResponse(Call<UserInfoModel> call, Response<UserInfoModel> response) {
                UserInfoModel body = response.body();
                String json = JsonUtils.toJson(body);
                Log.e("请求成功登陆", json);
            }

            @Override
            public void onFailure(Call<UserInfoModel> call, Throwable t) {

            }
        });

    }

    private void initView() {
        mCehsidenglu = (Button) findViewById(R.id.cehsidenglu);
        mCehsidenglu.setOnClickListener(this);
        mFragmentceshi = (Button) findViewById(R.id.fragmentceshi);
        mFragmentceshi.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.cehsidenglu:
                startActivity(LoginActivity.class);
                break;
            case R.id.fragmentceshi:
                startActivity(testmvpfragment.class);
                break;
        }
    }
}
